package com.skivingcloud.apiplatform.signature.exception;

import com.skivingcloud.common.utils.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class SignedExceptionHandler {

    @ExceptionHandler(SignedException.ReplayAttack.class)
    public R exceptionHandler(SignedException.ReplayAttack ex) {
        String msg = ex.getMessage();
        return R.error("接口入参可能已被篡改, " + msg);
    }

    @ExceptionHandler(SignedException.NullParam.class)
    public R exceptionHandler(SignedException.NullParam ex) {
        String msg = ex.getMessage();
        return R.error("参数 " + msg + " 是空的");
    }

    @ExceptionHandler(SignedException.AppIdInvalid.class)
    public R exceptionHandler(SignedException.AppIdInvalid ex) {
        String msg = ex.getMessage();
        return R.error(" appId " + msg + " 不合法");
    }

    @ExceptionHandler(SignedException.SignatureError.class)
    public R exceptionHandler(SignedException.SignatureError ex) {
        String msg = ex.getMessage();
        return R.error("数据验签失败: " + msg);
    }

    @ExceptionHandler(SignedException.TimestampError.class)
    public R exceptionHandler(SignedException.TimestampError ex) {
        String msg = ex.getMessage();
        return R.error("The time difference is too large: " + msg);
    }

    @ExceptionHandler(SignedException.WhiteListError.class)
    public R exceptionHandler(SignedException.WhiteListError ex) {
        String msg = ex.getMessage();
        return R.error("校验白名单异常: " + msg);
    }
}
